﻿Imports PadovadoAPI
Imports System.Data

Partial Class WebUserControls_CntlMeteo
    Inherits System.Web.UI.UserControl

    Public Property DataCorrente As DateTime
        Set(value As DateTime)
            ViewState("DataCorrente") = value
        End Set
        Get
            If ViewState("DataCorrente") = DateTime.MinValue Then ViewState("DataCorrente") = DateTime.Now
            Return ViewState("DataCorrente")
        End Get
    End Property

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        CaricaDati()
    End Sub

    Public Sub CaricaDati()

        Dim dbConnector As New DBObject
        Dim sql As String = ""
        sql = "SELECT ImgMeteo, TMax, TMin FROM Meteo WHERE DataRiferimento = CAST('" & DataCorrente.ToString("yyyyMMdd") & "' as date)"

        'Throw New Exception(sql)
        Dim ds As New DataSet
        ds = dbConnector.FillDS(sql, Nothing, 1)

        If Not IsNothing(ds) AndAlso ds.Tables.Count > 0 AndAlso ds.Tables(0).Rows.Count > 0 Then
            ' Throw New Exception(ds.Tables.Count)
            ImgMeteo.ImageUrl = ds.Tables(0).Rows(0).Item("ImgMeteo")
            LblMax.Text = "T° MAX: " & ds.Tables(0).Rows(0).Item("TMax")
            LblMin.Text = "t° min: " & ds.Tables(0).Rows(0).Item("TMin")

        End If


    End Sub
End Class
